<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="盲盒ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boxflId">
              <a-input-number v-model="model.boxflId" placeholder="请输入盲盒ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="盲盒名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boxflName">
              <a-input v-model="model.boxflName" placeholder="请输入盲盒名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="盲盒主图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="image">
              <j-image-upload isMultiple  v-model="model.image" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="用户ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <a-input-number v-model="model.userId" placeholder="请输入用户ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="支付方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payMethod">
              <j-dict-select-tag type="list" v-model="model.payMethod" dictCode="pay_method" placeholder="请选择支付方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="支付价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payCoin">
              <a-input-number v-model="model.payCoin" placeholder="请输入支付价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="商户订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outTradeNo">
              <a-input v-model="model.outTradeNo" placeholder="请输入商户订单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="微信平台订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="transactionId">
              <a-input v-model="model.transactionId" placeholder="请输入微信平台订单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="支付宝订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="alipayTradeNo">
              <a-input v-model="model.alipayTradeNo" placeholder="请输入支付宝订单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="付款时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payTime">
              <a-input-number v-model="model.payTime" placeholder="请输入付款时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="list" v-model="model.status" dictCode="order_status" placeholder="请选择状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="后台已读标识:1已读,0未读" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="backendRead">
              <a-input-number v-model="model.backendRead" placeholder="请输入后台已读标识:1已读,0未读" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="删除时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deleteTime">
              <a-input-number v-model="model.deleteTime" placeholder="请输入删除时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="终端" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="terminal">
              <j-dict-select-tag type="list" v-model="model.terminal" dictCode="terminal_type" placeholder="请选择终端" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
              <a-input-number v-model="model.num" placeholder="请输入数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="运费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryFee">
              <a-input-number v-model="model.deliveryFee" placeholder="请输入运费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="抵扣星石数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xingshi">
              <a-input v-model="model.xingshi" placeholder="请输入抵扣星石数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="是否已经抽过奖品" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ischou">
              <j-dict-select-tag type="list" v-model="model.ischou" dictCode="yn" placeholder="请选择是否已经抽过奖品" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'BoxOrderForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           outTradeNo: [
              { required: true, message: '请输入商户订单号!'},
           ],
           ischou: [
              { required: true, message: '请输入是否已经抽过奖品!'},
           ],
        },
        url: {
          add: "/order/boxOrder/add",
          edit: "/order/boxOrder/edit",
          queryById: "/order/boxOrder/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>